package Exc.controller;

import Exc.domain.*;
import Exc.service.IPersonalInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller()
@RequestMapping("/PersonalInformation")
public class PersonalAddressController {
    @Autowired
    private IPersonalInformationService personalInformationService;

    @RequestMapping("/list")
    @ResponseBody
    public JSONResult list() {
        List<PersonalInformation> personalInformationList = personalInformationService.listPersonal();
        JSONResult jsonResult = new JSONResult(true, "查询通讯录信息成功",personalInformationList);
        return jsonResult;
    }

    @RequestMapping("/add")
    @ResponseBody
    public JSONResult addOne(PersonalInformation personalInformation) {
        personalInformationService.saveInformation(personalInformation);
        JSONResult jsonResult = new JSONResult(true,"添加信息成功");
        return jsonResult;
    }

    @RequestMapping("/update")
    @ResponseBody
    public JSONResult update(PersonalInformation personalInformation) {
        personalInformationService.updateInformation(personalInformation);
        JSONResult jsonResult = new JSONResult(true,"更新信息成功");
        return jsonResult;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public JSONResult delete(String phoneNumber) {
        personalInformationService.deleteInformation(phoneNumber);
        JSONResult jsonResult = new JSONResult(true,"删除成功！");
        return jsonResult;
    }
}
